<html>
   
<?php
// boooooody al3b hena
 function displayStore($row){
     $count=count($row);
     for($i=0;$i < $count;$i++){                 
       $id=$row[$i]['storeID'];
       
echo "<div class=show >";
echo "<a href="."showProducts.php?action=showProducts&Sid=$id"."><img src='".$row[$i]['stImage']."' width=150 height=150  /></a>";

echo "<br/>";
  echo $row[$i]['storeName'];
echo $row[$i]['storeID'];
  echo "<br>";
  echo "</div>";
     
}
 }
 
$flag =false;

 if(isset($_POST['submitST'])){
     if(!isset($_SESSION))
session_start();
   if(isset($_SESSION['login']))
{  
    if((isset($_FILES['image'])) and ($_FILES['image']['name']!='')){
        $img="image";
         
       
    }
    else {
        $img=false;
       
    }
     $name= $_POST["storeName"]; 
     $location=$_POST["location"];
     $phone=$_POST["storephone"];
     include 'StoreClass.php';
     ////store fixed 3shan hn5do mn alsession b3d kda
     $us_id=$_SESSION['user_id'];
     
     $st= new Store($us_id, $name, $location, $phone, $img);
     //$st=new Store();
     //$result=$st->getStores();
   // $st->setData(6, $name, $location, $phone, $img);
    //$st->initStore();
    //$st->getStores();
     //$result=$st->getStoreByID(6);
    //displayStore($result);
   $stID =$st->getID($us_id);
    $_SESSION['store_id']=$stID[0]['storeID'];
    $id=$_SESSION['store_id'];
   // echo $id;
    header("location:showProducts.php?action=showProducts&Sid=$id");
} 
else
{
    header("Location:login.php");
}
 }
else if(isset($_POST['saveST'])){
     if(!isset($_SESSION))
session_start();
   if(isset($_SESSION['login']))
{  
    if((isset($_FILES['image'])) and ($_FILES['image']['name']!='')){
        $img="image";
         
       
    }
    else {
        $img=false;
       
    }
     $name= $_POST["storeName"]; 
     $location=$_POST["location"];
     $phone=$_POST["storephone"];
     include 'StoreClass.php';
     ////store fixed 3shan hn5do mn alsession b3d kda
     $us_id=$_SESSION['user_id'];
     $st=new Store();
    
   $stID =$st->getID($us_id);
    $_SESSION['store_id']=$stID[0]['storeID'];
    $id=$_SESSION['store_id'];
    try {
            $st->UpdateStore($id, $name, $location, $phone, $img);

    } catch (Exception $ex) {
       echo $ex->getMessage();
    
    }
   // echo $id;
    header("location:showProducts.php?action=showProducts&Sid=$id");
} 
else
{
    header("Location:login.php");
}
}
else if((@$_GET['action'] and @$_GET['action']=="stores")){
     include 'StoreClass.php';
      $st=new Store();
     $result=$st->getStores();
   // $st->setData(6, $name, $location, $phone, $img);
    //$st->initStore();
    //$st->getStores();
   $flag=true;
    include './stores.php';
    // $result=$st->getStoreByID(64);
    // displayStore($result);
}
else if(@$_GET['action'] and @$_GET['action']=="create")
{
    
    
     if(!isset($_SESSION))
     {
         session_start();
         
     }
   if(isset($_SESSION['login']))
{  
    include './createStoreForm.php';
}
else
    {
    header("Location:login.php");
}   
   
}else if(@$_GET['action'] and @$_GET['action']=="editST")
{
    
    
     if(!isset($_SESSION))
     {
         session_start();
         
     }
   if(isset($_SESSION['login']))
{  
       include './StoreClass.php';
       $id= $_SESSION['store_id'];
       $st=new Store();
       $stInfo=$st->getStoreByID($id);
      $name= $stInfo[0]['storeName']; 
     $location=$stInfo[0]["address"];
     $phone=$stInfo[0]['stPhone'];
     $image=$stInfo[0]['stImage'];
     $update='store';
    include './UpdateForm.php';
}
else
    {
    header("Location:login.php");
}   
    
}
else if(@$_GET['action'] and @$_GET['action']=="editPRO")
{
    
    
     if(!isset($_SESSION))
     {
         session_start();
         
     }
   if(isset($_SESSION['login']))
{  
       include './productClass.php';
     $pr=new Product();
     $proID=$_GET['Pid'];
     
     $result=   $pr->getProductByID($proID);
     $size=$result[0]['size']; 
     $price=$result[0]['price'];
     $quantity=$result[0]['quantity'];
     $category=$result[0]['category'];
      $image=$result[0]['proImage'];
     $ProductDescrpition="";
      
     $update='product';
    include './UpdateForm.php';
}
else
    {
    header("Location:login.php");
}   
    
}
    

    ?>
</html>
